package cn.iocoder.yudao.module.design.dal.mysql.relativednc;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.design.controller.admin.relativednc.vo.RelativedNcExportReqVO;
import cn.iocoder.yudao.module.design.controller.admin.relativednc.vo.RelativedNcPageReqVO;
import cn.iocoder.yudao.module.design.dal.dataobject.relativednc.RelativedNcDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 关联人表请求 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface RelativedNcMapper extends BaseMapperX<RelativedNcDO> {

    default PageResult<RelativedNcDO> selectPage(RelativedNcPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RelativedNcDO>()
                .eqIfPresent(RelativedNcDO::getUserId, reqVO.getUserId())
                .eqIfPresent(RelativedNcDO::getRelId, reqVO.getRelId())
                .betweenIfPresent(RelativedNcDO::getCreateTime, reqVO.getCreateTime())
                .betweenIfPresent(RelativedNcDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(RelativedNcDO::getFinishTime, reqVO.getFinishTime())
                .orderByDesc(RelativedNcDO::getId));
    }

    default List<RelativedNcDO> selectList(RelativedNcExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<RelativedNcDO>()
                .eqIfPresent(RelativedNcDO::getUserId, reqVO.getUserId())
                .eqIfPresent(RelativedNcDO::getRelId, reqVO.getRelId())
                .betweenIfPresent(RelativedNcDO::getCreateTime, reqVO.getCreateTime())
                .betweenIfPresent(RelativedNcDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(RelativedNcDO::getFinishTime, reqVO.getFinishTime())
                .orderByDesc(RelativedNcDO::getId));
    }

    List<Map> queryRelativedListByUserId(String relId);

    List<Map> queryRelativedReqListByUserId(String relId);

    /**
     * 校验关联关系请求  （同意  处理中） 是否存在
     * @param userId  登录人id
     * @param relId 关联人id
     * @return 记录数
     */
    int checkUserRelNcExists(@Param("userId") String userId , @Param("relId") String relId,@Param("roleId") String roleId);

    Set<Integer> getUserRelStatusList(@Param("userId")String userId, @Param("relId") String relId,@Param("roleId") String roleId);
}
